<template>
  <div class="parts">
    <Parts-Header title="搜索"></Parts-Header>
    <div class="partsMain">
        <div class="search">
            <input type="text" v-model="key" placeholder="请输入标题或商品关键字"><span @click="search()" class="search_btn">搜索</span>
        </div>
        <div class="upper">
            <span v-for="(list,index) in upper" :key="index" class="list" @click="btn(index)" :class="{active:index===partsIndex}">{{list}}</span>
        </div>
        <!-- <div class="clear"></div> -->
        <div class="sousuo">
              <img v-if="hide" class="search_pic fl" src="/static/img/no-data.png">
            <Home-Container :todos="todos"></Home-Container>
        </div>
        
        </div>
    </div>
    
</template>

<script>
import axios from "axios";
import PartsHeader from "../common/header";
import HomeContainer from './home/component/SuperContainer'
import { Navbar, TabItem } from "mint-ui";
export default {
  data() {
    return {
        key:"",
        hide:true,
      selected: "tab-container1",
      list: [],
      upper: ["综合","优惠券面额","销量","价格"],
      PartsUpper: [],
      PartsLower: [],
      todos:[],
      list:[],
      partsIndex: 0,
      page:1
    };
  },
  components: {
    HomeContainer,
    PartsHeader
  },
   mounted:function(){
    var _this=this
    this.scroll(this.todos)
  },
  created() {
    var _this = this;
  },
  methods: {

    search:function(orderby){
        var _this=this
        axios.get(
          "/api/common/goodspdd/list",
          {
        params:{
            q:_this.key,
            orderby:orderby
            }
        }
          ).then(function(res){
        // console.log(res.data.data.length)
        if(res.data.data.length<1){
            _this.hide=true;
        }else{
             _this.hide=false;
        }
        _this.todos=res.data.data
      })
    },
    btn(index) {
      var _this = this;   
      _this.partsIndex = index;
      _this.PartsLower = _this.list[index];
       var cat_id =this.$route.query.cat_id;
      var title =this.$route.query.title;
      if(index==1){
        var orderby=8;
        this.search(orderby);
      }else if(index==2){
        var orderby=6;
        this.search(orderby);
      }else if(index==3){
         var orderby=10;
        this.search(orderby);
      }else{
        this.search();
      }
    },
    scroll:function(data) {
       var _this=this
        // console.log(data)
        let isLoading = false
        window.onscroll = () => {
           
            let bottomOfWindow = document.documentElement.scrollHeight -document.documentElement.scrollTop - window.innerHeight <= 20
            if (bottomOfWindow && isLoading == false) {
                isLoading = true
                axios.get(
                    "/api/common/goodspdd/list",
                    {
                      params:{
                          page:_this.page+1,
                           q:_this.key
                        }
                    }
                    ).then(response => {
                        _this.page++;
                        console.log( _this.page)
                        for(var i=0;i<response.data.data.length;i++){
                            _this.todos.push(response.data.data[i])
                        }
            isLoading = false
                })
            }
        }
    }
  }
};
</script>


<style lang="stylus" scoped>
.clear{
    clear both
}
.sousuo{
    padding-top 2.3rem
}
.sousuo img{
    // margin-top 2rem;
    margin 2rem ;
    width 5.2rem
}
.active {
    border-bottom: 2px solid #ff4040;
}
.search{
    position fixed
    top 1rem
    height 1.2rem
    background-color #fff
    width 100%
    z-index 1
}
.search input{
    display inline-block
    height .8rem
    width 70%
    margin-bottom .3rem
    margin-left .4rem
    border 1px solid #ccc
}
.search .search_btn{
    font-size .36rem
    color #898989
    // float right 
    margin-left 1rem
}
.sort {
    width: 100%;
    height: 1rem;
    background: #f4f4f4;
    position: relative;
    top: 1.3rem;
    display: flex;
    z-index 3
    justify-content: center;
    p {
        line-height: 1rem;
        font-size: 0.35rem;
        float: left;
        width: 33%;
        text-align: center;
    }
}

.upper {
    width: 100%;
    height: 1.2rem;
    top 2.2rem
    line-height: 1.1rem;
    position: fixed;
    background: #ffffff;
    z-index: 1;
}

.lower {
    position: relative;
    top: 1.2rem;
    border-bottom: 1px solid #f4f4f4;
}

.list {
    float: left;
    text-align: center;
    width: 25%;
    font-size: 0.37rem;
}

.box {
    width: 100%;
    height: 1rem;
    background: #ecf0f1;
}

.parts {
    position: absolute;
    background #ffffff;
    width: 100%;
    height: 100%;
    top: 0;
    bottom: 0;
    z-index: 999;
}

.partsHeader {
    width: 100%;
    z-index: 1;
    height: 1.3rem;
    line-height: 1.3rem;
    font-size: 12px;
    background: white;
    position: fixed;
    -webkit-box-shadow: 0 0 10px #cecece;
    box-shadow: 0 0 10px #cecece;
    text-align: center;
    font-size: 0.41rem;
}

.partsHeader i {
    display: block;
    float: left;
    height: 50px;
    padding-left: 0.3rem;
    font-size: 0.71rem;
    color: black;
}

.partsMain {
    margin-top: 1.32rem;
}

.lower_list {
    height: 6.3rem;
    background: white;
    float: left;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    width: 50%;
    border-right: 1px solid #f4f4f4;
    border-bottom: 1px solid #f4f4f4;
    float: left;
    margin-top: 0.1rem;
    list-style: none;

    img {
        height: 3.6rem;
        width: 4rem;
        display: block;
        margin: auto;
        padding: 0.5rem;
    }

    h2 {
        width: 90%;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-size: 0.4rem;
        margin: auto;
        text-align: center;
        overflow: hidden;
    }

    p {
        width: 3.8rem;
        margin: 0 auto;
        padding: 0;
        height: 1.1rem;
        font-size: 0.22rem;
        line-height: 1.4;
        color: #000;
        word-break: break-all;
        padding-top: 0.2rem;
        text-align: center;
        overflow: hidden;
    }

    div {
        text-align: center;
        color: red;
        line-height: 1rem;
        font-size: 0.4rem;
    }
}
</style>
